#!/usr/bin/env python
# coding: utf-8

import threading
import asyncio

'''方法一'''
# @asyncio.coroutine
# def hello():
#     print('Hello world! (%s)' % threading.currentThread())
#     yield from asyncio.sleep(5)
#     print('Hello again! (%s)' % threading.currentThread())
'''方法二'''
async def hello():
    print('Hello world! (%s)' % threading.currentThread())
    await asyncio.sleep(5)
    print('Hello again! (%s)' % threading.currentThread())

loop = asyncio.get_event_loop()
tasks = [hello(), hello()]
loop.run_until_complete(asyncio.wait(tasks))
loop.close()

'''
异步执行：
Hello world! (<_MainThread(MainThread, started 140479604709120)>)
Hello world! (<_MainThread(MainThread, started 140479604709120)>)
大约等待5秒
Hello again! (<_MainThread(MainThread, started 140479604709120)>)
Hello again! (<_MainThread(MainThread, started 140479604709120)>)
'''